---
title: string
description: Creates a string schema.
source: /schemas/string/string.ts
contributors:
  - fabian-hiller
  - EltonLobo07
  - morinokami
  - jasperteo
  - kazizi55
---

import { ApiList, Property } from '~/components';
import { properties } from './properties';

# string

Creates a string schema.

```ts
const Schema = v.string<TMessage>(message);
```

## Generics

- `TMessage` <Property {...properties.TMessage} />

## Parameters

- `message` <Property {...properties.message} />

### Explanation

With `string` you can validate the data type of the input. If the input is not a string, you can use `message` to customize the error message.

## Returns

- `Schema` <Property {...properties.Schema} />

## Examples

The following examples show how `string` can be used.

### Email schema

Schema to validate an email.

```ts
const EmailSchema = v.pipe(
  v.string(),
  v.nonEmpty('Please enter your email.'),
  v.email('The email is badly formatted.'),
  v.maxLength(30, 'Your email is too long.')
);
```

### Password schema

Schema to validate a password.

```ts
const PasswordSchema = v.pipe(
  v.string(),
  v.minLength(8, 'Your password is too short.'),
  v.maxLength(30, 'Your password is too long.'),
  v.regex(/[a-z]/, 'Your password must contain a lowercase letter.'),
  v.regex(/[A-Z]/, 'Your password must contain a uppercase letter.'),
  v.regex(/[0-9]/, 'Your password must contain a number.')
);
```

### URL schema

Schema to validate a URL.

```ts
const UrlSchema = v.pipe(
  v.string('A URL must be string.'),
  v.url('The URL is badly formatted.')
);
```

## Related

The following APIs can be combined with `string`.

### Schemas

<ApiList
  items={[
    'array',
    'exactOptional',
    'intersect',
    'lazy',
    'looseObject',
    'looseTuple',
    'map',
    'nonNullable',
    'nonNullish',
    'nonOptional',
    'nullable',
    'nullish',
    'object',
    'objectWithRest',
    'optional',
    'record',
    'set',
    'strictObject',
    'strictTuple',
    'tuple',
    'tupleWithRest',
    'undefinedable',
    'union',
  ]}
/>

### Methods

<ApiList
  items={[
    'assert',
    'config',
    'fallback',
    'getDefault',
    'getDefaults',
    'getFallback',
    'getFallbacks',
    'is',
    'message',
    'parse',
    'parser',
    'pipe',
    'safeParse',
    'safeParser',
  ]}
/>

### Actions

<ApiList
  items={[
    'base64',
    'bic',
    'brand',
    'bytes',
    'creditCard',
    'cuid2',
    'check',
    'decimal',
    'description',
    'digits',
    'email',
    'emoji',
    'empty',
    'endsWith',
    'excludes',
    'flavor',
    'graphemes',
    'gtValue',
    'hash',
    'hexadecimal',
    'hexColor',
    'imei',
    'includes',
    'ip',
    'ipv4',
    'ipv6',
    'isbn',
    'isoDate',
    'isoDateTime',
    'isoTime',
    'isoTimeSecond',
    'isoTimestamp',
    'isoWeek',
    'json',
    'length',
    'ltValue',
    'mac',
    'mac48',
    'mac64',
    'maxBytes',
    'maxGraphemes',
    'maxLength',
    'maxValue',
    'maxWords',
    'metadata',
    'minBytes',
    'minGraphemes',
    'minLength',
    'minValue',
    'minWords',
    'nanoid',
    'nonEmpty',
    'notBytes',
    'notEntries',
    'notGraphemes',
    'notLength',
    'notValue',
    'notValues',
    'notWords',
    'octal',
    'parseJson',
    'rawCheck',
    'rawTransform',
    'readonly',
    'regex',
    'rfcEmail',
    'slug',
    'startsWith',
    'stringifyJson',
    'title',
    'toBigint',
    'toBoolean',
    'toDate',
    'toLowerCase',
    'toMaxValue',
    'toMinValue',
    'toNumber',
    'toUpperCase',
    'transform',
    'trim',
    'trimEnd',
    'trimStart',
    'ulid',
    'url',
    'uuid',
    'value',
    'values',
    'words',
  ]}
/>

### Utils

<ApiList items={['entriesFromList', 'isOfKind', 'isOfType']} />
